/**
 * @project_name staff_vehicle
 * @package_name com.ssh.web
 * @desc TODO
 * @param
 * @author jack
 * @date 2013-4-23
 * @time 下午5:16:39
 */
package com.ssh.web.caction;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.ssh.entity.AskForleave;
import com.ssh.ser.common.AskForLeaveSerI;

/**
 * @author jack
 *
 */
public class AskFLAction extends ActionSupport {
	/**
	 * TODO
	 */
	private static final long serialVersionUID = 1L;
	private Timestamp aflDate;
	private AskForLeaveSerI askForLeaveSerI;
	private Timestamp backDate;
	private List<AskForleave> MyAFLRList;
	private String reason;
	private String reviewerId;
	private String staffId;
	private int state;

	/*
	 * (non-Javadoc)
	 *
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		try {
			staffId = ServletActionContext.getRequest().getSession()
					.getAttribute("staffId").toString();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return viewMyAFLResult();
	}

	/**
	 * @return the aflDate
	 */
	public Timestamp getAflDate() {
		return aflDate;
	}

	/**
	 * @return the askForLeaveSerI
	 */
	public AskForLeaveSerI getAskForLeaveSerI() {
		return askForLeaveSerI;
	}

	/**
	 * @return the backDate
	 */
	public Timestamp getBackDate() {
		return backDate;
	}

	/**
	 * @return the myAFLRList
	 */
	public List<AskForleave> getMyAFLRList() {
		return MyAFLRList;
	}

	/**
	 * @return the reason
	 */
	public String getReason() {
		return reason;
	}

	/**
	 * @return the reviewerId
	 */
	public String getReviewerId() {
		return reviewerId;
	}

	/**
	 * @return the staffId
	 */
	public String getStaffId() {
		return staffId;
	}

	/**
	 * @param aflDate
	 *            the aflDate to set
	 */

	/**
	 * @return the state
	 */
	public int getState() {
		return state;
	}

	public String IWantToAFL() {
		HttpServletRequest request = ServletActionContext.getRequest();
		DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
		reviewerId = request.getParameter("name");
		staffId = request.getParameter("staffId");
		short aflDays = 1;
		try {
			aflDays = Short.parseShort(request.getParameter("aflDays"));
		} catch (Exception e) {
			aflDays = 1;
			e.printStackTrace();
		}
		try {
			state = Integer.parseInt(request.getParameter("state"));
		} catch (Exception e) {
			state = 0;
			e.printStackTrace();
		}
		reason = request.getParameter("reason");

		try {
			if(staffId!=null && !staffId.equals("")){
				AskForleave askFL = new AskForleave(staffId, "of00001", aflDate,
					backDate, "等待处理", aflDays, state, reason);
			askForLeaveSerI.addAskFL(askFL);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
		return "success";
	}

	/**
	 * @param aflDate
	 *            the aflDate to set
	 */
	public void setAflDate(Timestamp aflDate) {
		this.aflDate = aflDate;
	}

	/**
	 * @param askForLeaveSerI
	 *            the askForLeaveSerI to set
	 */
	public void setAskForLeaveSerI(AskForLeaveSerI askForLeaveSerI) {
		this.askForLeaveSerI = askForLeaveSerI;
	}

	/**
	 * @param backDate
	 *            the backDate to set
	 */
	public void setBackDate(Timestamp backDate) {
		this.backDate = backDate;
	}

	/**
	 * @param myAFLRList
	 *            the myAFLRList to set
	 */
	public void setMyAFLRList(List<AskForleave> myAFLRList) {
		MyAFLRList = myAFLRList;
	}

	/**
	 * @param reason
	 *            the reason to set
	 */
	public void setReason(String reason) {
		this.reason = reason;
	}

	/**
	 * @param reviewerId
	 *            the reviewerId to set
	 */
	public void setReviewerId(String reviewerId) {
		this.reviewerId = reviewerId;
	}

	/**
	 * @param staffId
	 *            the staffId to set
	 */
	public void setStaffId(String staffId) {
		this.staffId = staffId;
	}

	/**
	 * @param state
	 *            the state to set
	 */
	public void setState(int state) {
		this.state = state;
	}

	public String viewMyAFLResult() {
		try {
			MyAFLRList = askForLeaveSerI.viewAskFLList(staffId);
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}

		return "myAFLResult";
	}

}
